<template>
	<view>
		<view style="padding: 20rpx;">
			<view class="box">
				<uni-forms :modelValue="form" :rules="rules" ref="formRef" label-width="140rpx" label-align="right">
					<uni-forms-item label="身份证照片" name="avatar">
						<uni-file-picker limit="1" :image-styles="imageStyles" :del-icon="false" :disable-preview="true"
							fileMediatype="image" v-model="avatar" @select="handleAvatarUploadSuccess"></uni-file-picker>
					</uni-forms-item>
		
					<uni-forms-item label="身份证号码" name="cardNumber">
						<uni-easyinput type="textarea" v-model="form.cardNumber" placeholder="请输入您的身份证号" />
					</uni-forms-item>
					<uni-forms-item>
						<button type="primary" size="mini" @click="submitRider()">提 交 审 核</button>
					</uni-forms-item>
				</uni-forms>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: [],
				form:{},
				user: uni.getStorageSync('xm-user'),
				imageStyles: {
					"height": 100, // 边框高度
					"width": 200, // 边框宽度
					"border": { // 如果为 Boolean 值，可以控制边框显示与否
						"color": "#eee", // 边框颜色
						"width": "1px", // 边框宽度
						"style": "solid", // 边框样式
						"radius": "10%" // 边框圆角，支持百分比
					}
				},
			}
		},
		methods: {
			submitRider(){
				this.form.userId = this.user.id
				console.log(this.form)
				this.$request.post("/rider/add/submit",this.form).then(res => {
					if(res.code === '200'){
						uni.showModal({
							title:'重新登录',
							content:'申请提交成功,将返回到登录页面',
						})
						setTimeout(() => {
							uni.clearStorageSync();
							uni.navigateTo({
								url:'/pages/login/login'
							})
						},800)
					}else{
						uni.showModal({
							title:"错误",
							icon:'error',
							content:res.msg
						})
					}
				})
			},
			handleAvatarUploadSuccess(e) {
				let _this = this
				const filePath = e.tempFilePaths[0]
				uni.uploadFile({
					url: _this.$baseUrl + '/files/upload', //自己的后端接口（默认发送post请求） 注意 _this.$baseUrl需要在全局变量定义
					filePath: filePath,
					name: "file", //这里应为自己后端文件形参的名字
					success(res) {
						let url = JSON.parse(res.data || '{}').data // 获取返回的图像链接
						_this.form.cardImage = url // 给表单图像属性赋值
					}
				})
			},
		}
	}
</script>

<style>

</style>
